package org.boot.easyapi.core.util;

import org.boot.easyapi.util.ObjectUtil;
import org.boot.easyapi.util.StrUtil;

import java.util.Map;

import static org.boot.easyapi.exception.BusinessException.exception;

public class RespKeyUtil {

    /**
     * 处理请求参数中的respKey
     */
    public static String getRespKey(Map<String, Object> map){
        if (map != null){
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                if (entry.getKey().equals("respKey") || entry.getKey().equals("resp_key")) {
                    return entry.getValue().toString();
                }
            }
        }
        return null;
    }

    /**
     * 检查是否强制返回vo模式下，是否携带respKey参数
     */
    public static void checkRespKey(boolean onlyResponseVo, Object respKey){
        if (onlyResponseVo){
            if(ObjectUtil.isEmpty(respKey) || StrUtil.isEmpty(respKey.toString())){
                throw exception("强制respVo模式下，请携带参数：respKey");
            }
        }
    }
}
